package org.iabako.server.dao.support;

import org.iabako.server.dao.JpaDAO;
import org.iabako.server.tools.ServerTools;
import org.iabako.shared.entity.support.LogException;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by jose on 19/05/15.
 */

@Repository("logExceptionDAO")
public class LogExceptionDAO extends JpaDAO<Long, LogException> {

    @Override
    protected String getUniqueNumberVerificationQuery() {
        return null;
    }

    @Override
    protected String getLastNumberQuery() {
        return null;
    }

    public List<LogException> getExceptionByDate(Date date) {
        ServerTools serverTools = new ServerTools();
        date = serverTools.resetTime((Date) date.clone());
        Date datePlusOne = serverTools.addDaysToDate((Date) date.clone(), 1);
        String query = "SELECT log FROM LogException log WHERE log.date >= :date AND log.date < :datePlusOne";
        return entityManager.createQuery(query).setParameter("date", date).setParameter("datePlusOne", datePlusOne).getResultList();
    }
}
